package com.controller;

import com.model.Cart;
import com.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/elm/CartController")
public class CartController {
    @Autowired
    CartService service;

    @PostMapping("/listCart")
    public Object listCart(String userId, int businessId)throws Exception{
        List<Cart> carts = service.listCart(userId, businessId);
        return carts;
    }
    @PostMapping("/updateCart")
    public Object updateCart(String userId, int businessId, int foodId, int quantity)throws Exception{
        int i = service.updateCart(userId, businessId, foodId,quantity);
        return i;
    }
    @PostMapping("/removeCart")
    public Object removeCart(String userId, int businessId, int foodId)throws Exception{
        int i = service.removeCart(userId, businessId, foodId);
        return i;
    }
    @PostMapping("/removeCart1")
    public Object removeCart1(String userId, int businessId)throws Exception{
        int i = service.removeCart1(userId, businessId);
        return i;
    }
    @PostMapping("/saveCart")
    public Object saveCart(String userId, int businessId, int foodId)throws  Exception{
        int i = service.saveCart(userId, businessId, foodId);
        return i;
    }
}
